/**
 * 指的是出生日期，格式为"1990-01-01"
 */
function yearInterval(startYear) {
	var returnYear,
		startYearArr = startYear.split("-"),
		birthYear = startYearArr[0],
		birthMonth = startYearArr[1],
		birthDay = startYearArr[2],
		d = new Date(),
		nowYear = d.getFullYear(),
		nowMonth = d.getMonth() + 1,
		nowDay = d.getDate();
	if (nowYear == birthYear) {
		returnYear = 0; //同年
	} else {
		var yearDiff = nowYear - birthYear; //年之差
		if (yearDiff > 0) {
			if (nowMonth == birthMonth) {
				var dayDiff = nowDay - birthDay; //日之差
				if (dayDiff < 0) {
					returnYear = yearDiff - 1;
				} else {
					returnYear = yearDiff;
				}
			} else {
				var monthDiff = nowMonth - birthMonth; //月之差
				if (monthDiff < 0) {
					returnYear = yearDiff - 1;
				} else {
					returnYear = yearDiff;
				}
			}
		} else {
			returnYear = -1; //返回-1 表示输入错误
		}
	}
	return returnYear; //返回周岁年龄
}

export default {
	yearFilter(startYear) {
		return yearInterval(startYear)
	}
}
